<?php

/*
 * This file is part of PHP CS Fixer.
 * (c) xieyuhua <1510120461@qq.com>
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

define('SWOOLE_XYH_PATH', __DIR__ );

date_default_timezone_set('Asia/Shanghai');

require SWOOLE_XYH_PATH . '/Xphp/Xcloze/Loader.php';

use Xcloze\Jobs\JobObject;
use Xcloze\Jobs\Logs;
use Xcloze\Jobs\Queue\BaseTopicQueue;
use Xcloze\Jobs\Queue\Queue;









$config        = require_once SWOOLE_XYH_PATH . '/config.php';
$logger        = Logs::getLogger($config['logPath'] ?? '', $config['logSaveFileApp'] ?? '');
$queue         =Queue::getQueue($config['job']['queue'], $logger);

$queue->setTopics($config['job']['topics']);

if (!$queue) {
    die("queue object is null\n");
}

//jobs的topic需要在配置文件里面定义，并且一次性注册进去
$topics = $queue->getTopics();
//var_dump($topics); exit;

for ($i = 0; $i < 10000; ++$i) {
    $rand                  =mt_rand(0, 100);
    $delay                 = 0;
    $priority              =BaseTopicQueue::HIGH_LEVEL_1;
    $jobExtras['delay']    =$delay;
    $jobExtras['priority'] =$priority;
    $job                   = new JobObject('Redisname', '\app\index\Controller\PriceAction', 'push', ['测试1', time()], $jobExtras);
    //$job                   =new JobObject('MyJob', '\app\index\Controller\JobAction', 'test1', ['测试1', time()], $jobExtras);
    $result                =$queue->push('Redisname', $job, 1, 'json');
   // var_dump($job);
}
